#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iostream>

#include "../src/frsqrt.hh"

namespace 
{
using namespace flassol;

void
test_frsqrt_once (void)
{
  float x = drand48 ();
  float y = 1.0 / sqrtf (x);
  float z = rsqrtf (x);

  assert (fabs (y - z) <= 1e-6 * (1 + fabs (y) + fabs (z)) ||
          (std::cerr << "x = " << x << 
                       " y = " << y << " z = " << z << std::endl,
           0));
}

void
test_frsqrt (void)
{
  for (unsigned int n = 0; n < 10000; ++n)
    {
      test_frsqrt_once ();
    }
}

}

int 
main (void)
{
  flassol::init_rsqrt ();
  test_frsqrt ();

  return 0;
}
